package com.ujs.edu.medicine.dao;

import com.ujs.edu.medicine.dataobject.Author;
import com.ujs.edu.medicine.dataobject.YunjiayiUser;
import java.util.List;

import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;


@Mapper
public interface YunjiayiUserMapper {
    @Delete({
            "delete from yunjiayi_user",
            "where user_Id = #{userId,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer userId);

    @Insert({
            "insert into yunjiayi_user (user_Id, username, ",
            "password, sex, phonenumber, ",
            "identity_Id, avatar, ",
            "create_time, modify_time, ",
            "unit,money,",
             "age,content,",
             "statusID,realname)",
            "values (#{user_Id,jdbcType=INTEGER}, #{username,jdbcType=VARCHAR}, ",
            "#{password,jdbcType=VARCHAR}, #{sex,jdbcType=INTEGER}, #{phonenumber,jdbcType=VARCHAR}, ",
            "#{identityId,jdbcType=INTEGER}, #{avatar,jdbcType=VARCHAR}, ",
            "now(), now(), ",
            "#{unit,jdbcType=VARCHAR}, #{money,jdbcType=FLOAT}, #{age,jdbcType=VARCHAR}, " ,
            "#{content,jdbcType=VARCHAR}, #{statusID,jdbcType=INTEGER}, #{realname,jdbcType=VARCHAR})"
    })
    @Options(useGeneratedKeys = true,keyProperty = "user_Id",keyColumn = "user_Id")
    int insert(YunjiayiUser record);

    @Select({
            "select",
            "user_Id, username, password, sex, phonenumber, identity_Id, avatar, create_time, ",
            "modify_time,  unit,money,",
            "age,content,",
            "statusID,realname",
            "from yunjiayi_user",
            "where user_Id = #{userId,jdbcType=INTEGER}"
    })
    @Results({
            @Result(column="user_Id", property="user_Id", jdbcType=JdbcType.INTEGER, id=true),
            @Result(column="username", property="username", jdbcType=JdbcType.VARCHAR),
            @Result(column="password", property="password", jdbcType=JdbcType.VARCHAR),
            @Result(column="sex", property="sex", jdbcType=JdbcType.INTEGER),
            @Result(column="phonenumber", property="phonenumber", jdbcType=JdbcType.VARCHAR),
            @Result(column="identity_Id", property="identityId", jdbcType=JdbcType.INTEGER),
            @Result(column="avatar", property="avatar", jdbcType=JdbcType.VARCHAR),
            @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="modify_time", property="modifyTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="unit", property="unit", jdbcType=JdbcType.VARCHAR),
            @Result(column="money", property="money", jdbcType=JdbcType.FLOAT),
            @Result(column="age", property="age", jdbcType=JdbcType.VARCHAR),
            @Result(column="content", property="content", jdbcType=JdbcType.VARCHAR),
            @Result(column="statusID", property="statusID", jdbcType=JdbcType.INTEGER),
            @Result(column="realname", property="realname", jdbcType=JdbcType.VARCHAR)
    })
    YunjiayiUser selectByPrimaryKey(Integer userId);
    @Select({
            "select",
            "user_Id, avatar, realname",
            "from yunjiayi_user",
            "where user_Id = #{userId,jdbcType=INTEGER}"
    })
    @Results({
            @Result(column="user_Id", property="user_Id", jdbcType=JdbcType.INTEGER, id=true),
            @Result(column="avatar", property="avatar", jdbcType=JdbcType.VARCHAR),
            @Result(column="realname", property="realname", jdbcType=JdbcType.VARCHAR)
    })
    Author selectAuthorByPrimaryKey(Integer userId);

    @Select({
            "select",
            "user_Id, username, password, sex, phonenumber, identity_Id, avatar, create_time, ",
            "modify_time,  unit,money,",
            "age,content,",
            "statusID,realname",
            "from yunjiayi_user"
    })
    @Results(id = "userList",value={
            @Result(column="user_Id", property="user_Id", jdbcType=JdbcType.INTEGER, id=true),
            @Result(column="username", property="username", jdbcType=JdbcType.VARCHAR),
            @Result(column="password", property="password", jdbcType=JdbcType.VARCHAR),
            @Result(column="sex", property="sex", jdbcType=JdbcType.INTEGER),
            @Result(column="phonenumber", property="phonenumber", jdbcType=JdbcType.VARCHAR),
            @Result(column="identity_Id", property="identityId", jdbcType=JdbcType.INTEGER),
            @Result(column="avatar", property="avatar", jdbcType=JdbcType.VARCHAR),
            @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="modify_time", property="modifyTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="unit", property="unit", jdbcType=JdbcType.VARCHAR),
            @Result(column="money", property="money", jdbcType=JdbcType.FLOAT),
            @Result(column="age", property="age", jdbcType=JdbcType.VARCHAR),
            @Result(column="content", property="content", jdbcType=JdbcType.VARCHAR),
            @Result(column="statusID", property="statusID", jdbcType=JdbcType.INTEGER),
            @Result(column="realname", property="realname", jdbcType=JdbcType.VARCHAR)
    })
    List<YunjiayiUser> selectAll();


    /*分页查询*/
    @Select("select * from yunjiayi_user limit #{page},10")
    @ResultMap("userList")
    List<YunjiayiUser> selectByPage(@Param("page")Integer page);

    @Select({
            "select",
            "user_Id, username, password, sex, phonenumber, identity_Id, avatar, create_time, ",
            "modify_time,  unit,money,",
            "age,content,",
            "statusID,realname",
            "from yunjiayi_user",
            "where username=#{username}"
    })
    @ResultMap("userList")
    YunjiayiUser selectByName(@Param("username") String username);

    @Select({
            "select",
            "user_Id, username, password, sex, phonenumber, identity_Id, avatar, create_time, ",
            "modify_time,  unit,money,",
            "age,content,",
            "statusID,realname",
            "from yunjiayi_user",
            "where identity_Id=#{identity_Id}"
    })
    @ResultMap("userList")
    List<YunjiayiUser> selectByidcard(@Param("identity_Id") Integer identity_Id);

    /*获取用户部分信息*/
    @Select("select user_Id,avatar,realname from yunjiayi_user where user_Id=#{userId}")
    Author selectPartInfo(@Param("userId")Integer userId);
    /*获取完全验证用户列表，不分页*/
    @Select("SELECT * FROM `yunjiayi_user` where identity_Id !=0 and identity_Id !=1 and identity_Id !=2")
    @ResultMap("userList")
    List<YunjiayiUser> selectUesrByidentity();

    /*获取真实姓名*/
    @Select("select realname from yunjiayi_user where user_Id=#{userId}")
    String selectRealName(@Param("userId")Integer userId);

    @Update({
            "update yunjiayi_user",
            "set username = #{username,jdbcType=VARCHAR},",
            "password = #{password,jdbcType=VARCHAR},",
            "sex = #{sex,jdbcType=INTEGER},",
            "phonenumber = #{phonenumber,jdbcType=VARCHAR},",
            "identity_Id = #{identityId,jdbcType=INTEGER},",
            "avatar = #{avatar,jdbcType=VARCHAR},",
            "create_time = now(),",
            "modify_time = now(),",
            "unit= #{unit,jdbcType=VARCHAR},",
            "money= #{money,jdbcType=FLOAT},",
            "age= #{age,jdbcType=VARCHAR}, " ,
            "content=#{content,jdbcType=VARCHAR}," ,
            "statusID=#{statusID,jdbcType=INTEGER},",
            "realname=#{realname,jdbcType=VARCHAR}",
            "where user_Id = #{user_Id,jdbcType=INTEGER}",

    })
    int updateByPrimaryKey(YunjiayiUser record);
}